package old.dbutils;

import java.sql.Connection;
import java.util.Date;
import java.util.List;

/**
 * @author DingZhenYun
 * @create 2019-03-21 20:33
 */
public class CustomerDaoTest {

    public static void main(String[] args) {
        //testget();
        //testupdate();
        testList();
        testone();
        testbatch();
    }

    private static void testget() {
        CustomerDao customerDao=new CustomerDao();
        try{
            String sql="select * from customer where id=?";
            Customer customer=customerDao.get(sql,1);
            System.out.println(customer);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private static void testupdate() {
        CustomerDao customerDao=new CustomerDao();
        try{

            String sql="update customer set name=? where id=?";
            customerDao.update(sql,"dd",2);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private static void testList() {
        CustomerDao customerDao=new CustomerDao();
        try{

            String sql="select * from customer";
            List<Customer> customers=customerDao.getForList(sql);
            System.out.println(customers);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private static void testone() {
        CustomerDao customerDao=new CustomerDao();
        try{
            String sql="select count(*) from customer";
      Object customers=customerDao.getForValue(sql);
            System.out.println(customers);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    private static void testbatch() {
        CustomerDao customerDao=new CustomerDao();

        try{


            for (int i = 0; i <100 ; i++) {
                String sql="insert into customer(id,name,email,birth) values(?,?,?,?)";

                customerDao.batch(sql,new Object[]{i+11,"dd"+i,"ddd"+i,new Date()});
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
